import {createSlice} from "@reduxjs/toolkit"

const userSlice=createSlice({
    name:"user",
    initialState:{
        user:localStorage.user ? JSON.parse(localStorage.user) : {},
        activeKey:localStorage.activeKey ? localStorage.activeKey : "",
    },
    reducers:{
        setUserInfo(state,action){
            state.user=action.payload;
            localStorage.user=JSON.stringify(action.payload);
        },
        clearUserInfo(state,action){
            state.user=action.payload;
            localStorage.user=JSON.stringify(action.payload);
        },
        setActiveKey(state,action){
            state.activeKey=action.payload;
            localStorage.activeKey=action.payload;
        }
    }
});
export const {setUserInfo,clearUserInfo,setActiveKey}=userSlice.actions;
export default userSlice;